home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 September / Chip_2000-09_cd1.bin / sharewar / Slunec / app / 16 / MOD.SWG / 0061_MDL Digitrakker MODule v3.1.pas < prev    next >
Pascal/Delphi Source File  |  1997-05-11  |  22KB  |  479 lines

  1.                                                       ┌─-─--·· · · ··--─-─┐
  2. ╒═════════════════════════════════════════════════════│    █▐  n-Factor's │══╕
  3. ├─────────────────────────────────────────────────────│    █▐             │──┤
  4. │                                                     │ ▐███▐  ▀ ▐███▌  ▀ │  │
  5. │   ≡≡≡ DIGITRAKKER ≡≡≡ FILE-FORMAT DESCRIPTION ≡≡≡   │ █  █▐ █▐ █  █▐ █▐ │  │
  6. │                                                     │ ▐███▐ █▐ ▐███▐ █▐ │  │
  7. ├─────────────────────────────────────────────────────│             █▐    │──┤
  8. ╘═════════════════════════════════════════════════════│  t r a k k▐██▌e r │══╛
  9.                                                       └─-─--·· · · ··--─-─┘
  10.  
  11. --------------------------- by prodatron/n-Factor ----------------------------
  12. revision 3.1
  13.  
  14.  
  15. This  file  contains information about  the songmodule-format "MDL", the
  16. instrument-format  "IST"  and the old  sample-format  "SPL". If you have
  17. some  problems  or if you have  questions about these formats, which are
  18. not answered in here, just contact me (eMail: pdt@uni-duisburg.de).
  19.  
  20. ╔════════════════════════════════════════════════════════════════════════════╗
  21. ║                        THE SONGMODULE-FORMAT  (MDL)                   V1.1 ║
  22. ╚════════════════════════════════════════════════════════════════════════════╝
  23.  
  24. Offset Lenght Description
  25.  
  26.  000    004     "DMDL"; the four letters mark the mdl-format
  27.  004    001     version; the current version is 11h (=1.1)
  28.  005    ???     the different data-blocks are stored at this position
  29.  
  30. Some words to the format version-number:
  31. - if the low-nibble increases, there are extensions in the format, but old
  32.   loaders should be able to load the new modules (or most of them...)
  33. - if the high-nibble increases, there are changes in the format which make old
  34.   loaders unable to read the new songfiles
  35.  
  36. The MDL-songmodule-format is subdivided into the following blocks:
  37.  
  38. "IN"    infoblock; contains most songparameters, like speed, length etc.
  39. "ME"    songmessage; contains the songinformation from the composer
  40. "PA" c  pattern; contains the length, names and tracklists for every pattern
  41. "TR"    tracks; contains all the tracks for the pattern
  42. "II" n  instruments; contains all information for the used instruments
  43. "VE" n  volume-envelopes; contains the construction of all used vol-envelopes
  44. "PE" n  panning-envelopes; the same for the used pan-envelopes
  45. "FE" n1 frequency-envelopes; ...used frq-envelopes (LFO)
  46. "IS" c  sampleinfos; contains information for every used sample
  47. "SA"    samples; contains the sample-datas
  48.  
  49. [[ c  = blockstructure changes from v0.0 to v1.0 ]]
  50. [[ n  = new in version 1.0                       ]]
  51. [[ n1 = new in version 1.1                       ]]
  52.  
  53. The  sequence of the blocks in a file is not fixed so they can be stored
  54. in any way. Digitrakker uses the descripted sequence.
  55.  
  56. The structure for every block is the same:
  57.  
  58. Offset Lenght Description
  59.  
  60.  000    002     "xx"; block-ID (example: "IN" for infoblock)
  61.  002    004     blocklength; this dword contains the length of the FOLLOWING
  62.         datas.
  63.  006 <blocklen> datas for this block...
  64.  
  65. The next block will be at offset (006 + <blocklength>).
  66.  
  67. ┌────────────────────────────────────────────────────────────────────────────┐
  68. │                          The Song-Infoblock  (IN)                          │
  69. └────────────────────────────────────────────────────────────────────────────┘
  70.  
  71. Offset Lenght Description
  72.  
  73.  000    002     "IN"; infoblock-ID
  74.  002    004     blocklenght
  75.  006    032     songname; name of the songmodule (filled with spaces [32])
  76.  038    020     composername; name of the song-composer
  77.  058    002     songlength; Digitrakker supports up to 255 songpositions
  78.  060    002     songrepeat
  79.  062    001     mainvolume (001-255)
  80.  063    001     song-speed (001-255)
  81.  064    001     beats per minute (004-255)
  82.  065    032     channel-information: bit 0-6 - panposition (0=left,127=right)
  83.                      bit 7   - 0=channel on, 1=channel off
  84.                 [number of channels = last active channel]
  85.  097  <snglen>  sequencer; contains the number of the pattern for every
  86.         songposition
  87.  ???  <chnnam>  the names for every channel (8 chars for one name).
  88.         <chnnam> = 8 * <number of channels>
  89.  
  90. ┌────────────────────────────────────────────────────────────────────────────┐
  91. │                            The Songmessage (ME)                            │
  92. └────────────────────────────────────────────────────────────────────────────┘
  93.  
  94. Offset Lenght Description
  95.  
  96.  000    002     "ME"; songmessage-ID
  97.  002    004     blocklenght
  98.  006    ???     songmessage; every line is closed with the CR-char (13). A
  99.         0-byte stands at the end of the whole text.
  100.  
  101. ┌────────────────────────────────────────────────────────────────────────────┐
  102. │                           The Patterndatas  (PA)                           │
  103. └────────────────────────────────────────────────────────────────────────────┘
  104.  
  105. Offset Lenght Description
  106.  
  107.  000    002     "PA"; patterndata-ID
  108.  002    004     blocklenght
  109.  006    001     number of pattern; values from 1 to 255 are possible
  110.  007  <patlar>  the datablocks for all saved pattern
  111.  
  112. The structure of one pattern-datablock:
  113.  
  114.  000    001    number of used channels (0-32)
  115.  001    001     patternlength-1 (0-255 for 1-256 lines)
  116.  002    016    pattern-name (filled with [32])
  117.  018  <trklar>  tracksequencing-list
  118.         <trklar> = 2 * number of channels in this pattern
  119.  
  120. The tracksequencing-lists descripe which track is used as which voice in
  121. the  pattern. The first word in this list  is the number of the track at
  122. voice  0. The second is track for voice 1 and so on... As every track is
  123. saved  independend,  it  is  possible to  save  some  discspace  by this
  124. methode:  If the song contains equal  tracks at several positions in the
  125. patterns,  these double tracks will only saved  one time. Track 0 is not
  126. saved and represents an empty track.
  127.  
  128. ┌────────────────────────────────────────────────────────────────────────────┐
  129. │                            The Trackdatas  (TR)                            │
  130. └────────────────────────────────────────────────────────────────────────────┘
  131.  
  132. Offset Lenght Description
  133.  
  134.  000    002     "TR"; trackdata-ID
  135.  002    004     blocklenght
  136.  006    002     number of tracks
  137.  008    ???     track-datablocks; every trackdatablock is stored in this way:
  138.         Ofs.000 Len.002         length of the trackdatas
  139.             002 <trackdatalen>  datas for this track
  140.  
  141. Every  track  consists  of  1-256  notepositions  and  every notposition
  142. contains 6 bytes:
  143.  
  144. byte 0              - note-value; 1 = C-0, 2 = C#0,..., 120 = B-9,
  145.               0 = nothing (---), 255 = key off (^^^)
  146. byte 1              - instrument-number; 1-255; 0 = nothing
  147. byte 2              - volume; 1-255; 0 = no volume change
  148. byte 3, low nibble  - number of the first effect-command
  149. byte 3, high nibble - number of the second effect-command (commands "g"-"l"
  150.               get the numbers 1-6)
  151. byte 4              - databyte for the first effect-command
  152. byte 5              - databyte for the second effect-command
  153.  
  154. Digitrakker  stores  the tracks in a  packed  way. The structure of this
  155. VERY effective (!!!) packformat is the following:
  156.  
  157.      bit 76543210
  158. byte 0 - xxxxxxyy
  159.  
  160. if yy = 00 -> <xxxxxx>+1 is the number of the empty notepositions which are
  161.           following.
  162. if yy = 01 -> the last noteposition will be repeated <xxxxxx>+1 times.
  163. if yy = 10 -> the noteslot from position <xxxxxx> is copied to the actual
  164.           position.
  165. if yy = 11 -> the following datas will be put in the actual noteslot:
  166.         bit 2 = 1 -> note
  167.         bit 3 = 1 -> sample
  168.         bit 4 = 1 -> volume
  169.         bit 5 = 1 -> effectcommand numbers
  170.         bit 6 = 1 -> databyte for effect 1
  171.         bit 7 = 1 -> databyte for effect 2
  172.               If the bit is not setted, the byte isn't stored and you have to
  173.               take 0 instead.
  174.  
  175. To find out the number of notepositions in a track you should decrease a
  176. counter  (startvalue: length of the  packed trackdatas) while depacking.
  177. Every  depacked track has to be filled  out with 0-values up to position
  178. 256.  When  you  copy the track into  a  pattern just take the number of
  179. positions  you  need for the pattern (if  the pattern has a length of 64
  180. positions only take the first 64 positions from the track).
  181.  
  182. ┌────────────────────────────────────────────────────────────────────────────┐
  183. │                           The Instruments (II)                             │
  184. └────────────────────────────────────────────────────────────────────────────┘
  185.  
  186. Offset Lenght Description
  187.  
  188.  000    002     "II"; intrument-ID
  189.  002    004     blocklenght
  190.  006    001     number of saved instruments; values from 0 to 255 are possible
  191.  007  <inslar>  the datablocks for all used instruments
  192.  
  193. The structure of one instrument-datablock:
  194.  
  195.  000    001     instrument-number; (1-255)
  196.  001    001    number of samples in instrument; (1-16)
  197.  001    032     instrument-name; the name of the instrument (filled with [32])
  198.  033  <is-len>  this block contains the infos for all defined samples in the
  199.         instrument; every info consist of 14 bytes, so
  200.         <is-len> = 14 * number of defined samples
  201.  
  202. The structure of one instrument-sample datablock:
  203.  
  204.  000    001     sample-number; (1-255)
  205.  001    001     playrange-end (0-119,0='c-0'); the last note for this sample;
  206.         a higher note uses one of the next samples
  207.  002    001     volume (1-255)
  208.  003    001     bit 0-5 -> volumeenvelope-number (0-63)
  209.         bit 6   -> flag, if volume is used
  210.         bit 7   -> flag, if volumeenvelope is used
  211.  004    001     panning (0-127)
  212.  005    001     bit 0-5 -> panningenvelope-number (0-63)
  213.         bit 6   -> flag, if panning is used
  214.         bit 7   -> flag, if panningenvelope is used
  215.  006    002     fadeout-speed (0-65535)
  216.  008    001     vibrato-speed (0-255)
  217.  009    001     vibrato-depth (0-255)
  218.  010    001     vibrato-sweep (0-255)
  219.  011    001     vibrato-form (0-2)
  220.  012    001     ** reserved ** (should be set to <0>)
  221.  013    001     bit 0-5 -> frequencyenvelope-number (0-63)
  222.                 bit 6   -> ** reserved ** (should be set to <0>)
  223.                 bit 7   -> flag, if frequencyenvelope is used
  224.  
  225. ┌────────────────────────────────────────────────────────────────────────────┐
  226. │                         The Volume-Envelopes  (VE)                         │
  227. └────────────────────────────────────────────────────────────────────────────┘
  228.  
  229. Offset Lenght Description
  230.  
  231.  000    002     "VE"; volume-envelope-ID
  232.  002    004     blocklenght
  233.  006    001     number of saved vol-envelopes (0-64)
  234.  007  <ve-lar>  volume-envelope datas; a datablock contains 33 bytes, so
  235.         <ve-lar> = 33 * number of saved vol-envelopes;
  236.  
  237. The structure of one envelope-datablock:
  238.  
  239.  000    001     envelope-number; (0-63)
  240.  001    030     the positions of the 15 points are stored here; the first
  241.         byte is the x-distance from the last point (1-255; 0 means,
  242.         that no more points are defined; take 1 for the first point),
  243.                 the second byte is the y-position (0-63)
  244.  031    001     bit 0-3 -> sustain-point (0-14)
  245.         bit 4   -> flag, if sustain is on
  246.         bit 5   -> flag, if loop is on
  247.                 bit 6-7 -> ** reserved ** (should be set to <0>)
  248.  032    001     bit 0-3 -> loop-start (0-14)
  249.         bit 4-7 -> loop-end (0-14)
  250.  
  251. ┌────────────────────────────────────────────────────────────────────────────┐
  252. │                         The Panning-Envelopes (PE)                         │
  253. └────────────────────────────────────────────────────────────────────────────┘
  254.  
  255. Offset Lenght Description
  256.  
  257.  000    002     "PE"; panning-envelope-ID
  258.  002    004     blocklenght
  259.  006    001     number of saved pan-envelopes (0-64)
  260.  007  <pe-lar>  panning-envelope datas; a datablock contains 33 bytes, so
  261.         <pe-lar> = 33 * number of saved pan-envelopes
  262.         see at "VE" for the description of an envelope-datablock
  263.  
  264. ┌────────────────────────────────────────────────────────────────────────────┐
  265. │                        The Frequency-Envelopes (FE)                        │
  266. └────────────────────────────────────────────────────────────────────────────┘
  267.  
  268. Offset Lenght Description
  269.  
  270.  000    002     "FE"; frequency-envelope-ID
  271.  002    004     blocklenght
  272.  006    001     number of saved frq-envelopes (0-64)
  273.  007  <fe-lar>  frequency-envelope datas; a datablock contains 33 bytes, so
  274.                 <fe-lar> = 33 * number of saved frq-envelopes
  275.         see at "VE" for the description of an envelope-datablock
  276.  
  277. ┌────────────────────────────────────────────────────────────────────────────┐
  278. │                         The Sample-Infoblocks (IS)                         │
  279. └────────────────────────────────────────────────────────────────────────────┘
  280.  
  281. Offset Lenght Description
  282.  
  283.  000    002     "IS"; sampleinfo-ID
  284.  002    004     blocklenght
  285.  006    001     number of saved samples; values from 0 to 255 are possible
  286.  007  <samlar>  sample-infoblocks; an infoblock for one sample contains 59
  287.                 bytes, so <samlar> = 59 * number of saved samples
  288.  
  289. The structure of one sample-infoblock:
  290.  
  291.  000    001     sample-number; (1-255)
  292.  001    032     sample-name; the name of the sample (filled with [32])
  293.  033    008     filename of the sample
  294.  041    004     C-4 sample-frequency in hz
  295.  045    004     sample-length
  296.  049    004     sample-repeatstart
  297.  053    004     sample-repeatlength; if this value is set to 0, the sample
  298.         will not loop
  299.  057    001     ** not used ** (this was the volume in old v0.0-modules)
  300.  058    001     infobyte:
  301.         bit 0   -> 0=8 bit sample, 1=16 bit sample
  302.         bit 1   -> 0=forward looping, 1=bidirectional looping
  303.                 bit 2,3 -> packmethode (0=not packed, 1=8bit packing,
  304.                            2=16bit packing, 3=not defined)
  305.                 bit 4-7 -> ** reserved ** (should be set to <0>)
  306.  
  307. ┌────────────────────────────────────────────────────────────────────────────┐
  308. │                            The Sampledatas (SA)                            │
  309. └────────────────────────────────────────────────────────────────────────────┘
  310.  
  311. Offset Lenght Description
  312.  
  313.  000    002     "SA"; sampledata-ID
  314.  002    004     blocklenght
  315.  006    ???     sampledatas; samples are stored in numeric sequence
  316.  
  317. Unpacked samples are stored in signed form. Packmethode (1) is designed for
  318. 8 bit samples, Packmethode (2) for 16 bit samples. Methode (3) isn't defined
  319. in this version.
  320. A packed sample begins with a dword which contains the length of the
  321. following datastream.
  322.  
  323.  
  324. The description of the sample-packmethode (1) [8bit packing]:...
  325. ────────────────────────────────────────────────────────────────
  326.  
  327. This  methode is based on the  huffman-algorithm. It's an easy form, but
  328. very   fast   and  effective  on  samples.   The   packed  sample  is  a
  329. bit-datastream:
  330.  
  331.     Byte 0    Byte 1    Byte 2    Byte 3
  332. Bit 76543210  fedcba98  nmlkjihg  ....rqpo
  333.  
  334. A packed byte is stored in the following form:
  335.  
  336. xxxx10..0s => byte = <xxxx> + (number of <0>-bits between s and 1) * 16 - 8 ;
  337.           if s=1 then byte = byte xor 255
  338.  
  339. If  there are no <0>-bits between the  first bit (sign) and the <1>-bit,
  340. you have the following form:
  341.  
  342. xxx1s      => byte = <xxx> ; if s=1 then byte = byte xor 255
  343.  
  344. To depack one byte, you have to use the following algorithm:
  345. ┌────────────────────────────────────────────────────────────────────────────┐
  346. │       read bit                                                             │
  347. │       sign = bit                                                           │
  348. │       read bit                                                             │
  349. │       if bit = 1                                                           │
  350. │               then  read [3bits]                                           │
  351. │                     byte = [3bits]                                         │
  352. │                     goto next                                              │
  353. │               else  byte = 8                                               │
  354. │loop:  read bit                                                             │
  355. │       if bit = 0                                                           │
  356. │               then  byte = byte + 16                                       │
  357. │                     goto loop                                              │
  358. │               else  read [4bits]                                           │
  359. │                     byte = byte + [4bits]                                  │
  360. │next:  if sign = 1                                                          │
  361. │               then byte = byte xor 255                                     │
  362. └────────────────────────────────────────────────────────────────────────────┘
  363.  
  364. Two examples:
  365.  
  366. xxxx  s
  367. 1001101 = ( 9 + 1 * 16 - 8 ) xor 255 = 238
  368.  
  369. xxx s
  370. 01010 = 2
  371.  
  372. Note  that the depacked bytes are delta  values. To convert them to real
  373. data use this algorithm:
  374.  
  375. oldbyte = 0
  376. for sampleposition = 1 to samplelength
  377.     newbyte = byte [sampleposition] + oldbyte
  378.     byte [sampleposition] = newbyte
  379.     oldbyte = newbyte
  380. next sampleposition
  381.  
  382.  
  383. The description of the sample-packmethode (2) [16bit packing]:...
  384. ────────────────────────────────────────────────────────────────
  385.  
  386. It  works as methode (1) but it  only crunches every 2nd byte (the high-
  387. bytes of 16 bit samples). So when you depack 16 bit samples, you have to
  388. read  8 bits from the data-stream first. They present the lowbyte of the
  389. sample-word.  Then  depack the highbyte  in  the descripted way (methode
  390. [1]).  Only the highbytes are delta-values. So take the lowbytes as they
  391. are. Go on this way for the whole sample!
  392.  
  393.  
  394. ┌────────────────────────────────────────────────────────────────────────────┐
  395. │                    ** Differences to older formats **                      │
  396. └────────────────────────────────────────────────────────────────────────────┘
  397.  
  398. Changes from v0.0 to v1.0:
  399. - block "PN" (patternnames) doesn't exist in v1.0-modules (patternnames now
  400.   stored in block "PA")
  401.   the old v0.0 structure of the "PN"-block:
  402.     000    002     "PN"; patternnames-ID
  403.     002    004     blocklenght
  404.     006  <patnam>  the names for every pattern (16 chars for one name).
  405.            <patnam> = 16 * <number of patterns>
  406. - structure of block "PA" changes completely
  407.   the old v0.0 structure of the "PA"-block:
  408.     000    002     "PA"; patterndata-ID
  409.     002    004     blocklenght
  410.     006    001     number of pattern; values from 1 to 255 are possible
  411.     007  <patlar>  tracksequencing-list for the used patterns;
  412.            <patlar> = 64 * number of patterns (32 words with the
  413.            tracknumbers for every pattern)
  414. - new blocks in v1.0-modules: "II" (instruments), "VE" (volume-envelopes) and
  415.   "PE" (panning-envelopes)
  416. - volumebyte (byte 57) in the sample-datablocks (block "IS") isn't used;
  417.   the C-4 sample-frequency increases from a word (2 bytes) to a dword (4
  418.   bytes), so one whole sample-infoblock now has a length of 59 bytes
  419.  
  420. Extension from v1.0 to v1.1:
  421. - new block: "FE" (frequency-envelopes)
  422.  
  423. ╔════════════════════════════════════════════════════════════════════════════╗
  424. ║                        THE INSTRUMENT-FORMAT  (IST)                   V0.1 ║
  425. ╚════════════════════════════════════════════════════════════════════════════╝
  426.  
  427. The IST-format has the same structure like parts the MDL-format:
  428.  
  429. Offset Lenght Description
  430.  
  431.  000    004     "DIST"; the four letters mark the ist-format
  432.  004    001     version; the current version is 01h (=0.1)
  433.  005    ???     the different data-blocks are stored at this position
  434.  
  435. The IST-instrument-format is subdivided into the following blocks:
  436.  
  437. "II"    instruments; contains all information for the saved instrument
  438. "VE"    volume-envelopes; contains the construction of all vol-envelopes for
  439.         this instrument
  440. "PE"    panning-envelopes; the same for the pan-envelopes
  441. "FE"    frequency-envelopes (new in v0.1); the same for the frq-envelopes
  442. "IS"    sampleinfos; contains information for every used sample
  443. "SA"    samples; contains the sample-datas
  444.  
  445. The structures for the several blocks are the same as in the mdl-format.
  446. The instrument-infoblock ("II") contains one instrument only.
  447.  
  448. ╔════════════════════════════════════════════════════════════════════════════╗
  449. ║                          THE SAMPLE-FORMAT  (SPL)                     V0.0 ║
  450. ╚════════════════════════════════════════════════════════════════════════════╝
  451.  
  452. Here  comes  the description for the  old sample-format "SPL", which was
  453. used  in older tracker-versions (V2.0-V2.2). This format isn't supported
  454. any  longer  in Digitrakker, that means you  can  read it, but you can't
  455. save  samples in this form. The reason  for this step was the fact, that
  456. there  are too many sample-formats and it  makes no sense to introduce a
  457. new  one, because the existing IFF-format  nearly contains all infos you
  458. need for a Digitrakker-sample.
  459.  
  460. Offset Lenght Description
  461.  
  462.  000    004     "DSPL"; the four letters mark the spl-format
  463.  004    001     version; the current version is 0
  464.  005    032     sample-name; the name of the sample (filled with [32])
  465.  037    008     filename of the sample
  466.  045    002     C-4 sample-frequency in hz (00000-65535)
  467.  047    004     sample-length
  468.  051    004     sample-repeatstart
  469.  055    004     sample-repeatlength; if this value is set to 0, the sample
  470.         will not loop
  471.  059    001     sample-volume (1-255)
  472.  060    001     infobyte:
  473.         bit 0   -> 0=8 bit sample, 1=16 bit sample
  474.         bit 1   -> 0=forward looping, 1=bidirectional looping
  475.         bit 2,3 -> packmethode (0=not packed, methodes 2 and 3 doesn't
  476.                exist in this version)
  477.         bit 4-7 -> not used (should be set to 0)
  478.  061    ???     sampledatas... (see above)
  479.